package com.dsl.utils;

import com.dsl.entity.User;
import org.springframework.stereotype.Component;

/**
 * @Description 持有用户信息，用于代替session对象，起到容器作用
 * @Author dsl
 * @Date 2024/9/6 下午10:22
 * @Version 1.0
 */
@Component
public class HostHolder {

    private final ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user){
        users.set(user);
    }

    public User getUser(){
        return users.get();
    }

    public void clear(){
        users.remove();
    }
}
